#define USE_STM32_SPI
#define USE_STM32_GPIO

#include "Stm32SoftSPI.h"
#include "SoftSPI.h"
#include "stm32_time.h"

#define DODELAY  stm_delayUs(5)


static u8 SPI_MASK[] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};


void Soft_SPI_Open(void)
{
	SPI_PORT_INIT();
}


void Soft_SPI_WriteByte(u8 wdata)
{
	u8 i = 0;
	SPI_MOSI_L;
	do 
	{
		SPI_CLK_L;

		if (wdata & SPI_MASK[i]){
			SPI_MOSI_H;
		}
		else{
			SPI_MOSI_L;
		}

		DODELAY;

		SPI_CLK_H;
		
	}while((++i) < 8);
}


u8 Soft_SPI_ReadByte(void)
{
	u8 i     = 0;
	u8 ret = 0;
	SPI_MOSI_L;
	do
	{
		SPI_CLK_L;

		DODELAY;

		if (SPI_MISO_I != (uint32_t)Bit_RESET){
			ret |= SPI_MASK[i];
		}

		SPI_CLK_H;
	}while((++i) < 8);

	return ret;
}

